package io.renren.controller;


import io.renren.entity.SysTreeTestEntity;
import io.renren.service.SysTreeTestService;
import io.renren.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-06-13 16:52:10
 */
@RestController
@RequestMapping("systreetest")
public class SysTreeTestController {
    @Autowired
    private SysTreeTestService sysTreeTestService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("systreetest:list")
    public
    @ResponseBody
    Map<String, List<SysTreeTestEntity>>
    list() {
        //查询列表数据
        List<SysTreeTestEntity> sysTreeTestList = sysTreeTestService.queryListAll();
        Map<java.lang.String, List<SysTreeTestEntity>> map = new HashMap<>();
        for (SysTreeTestEntity sysTreeTestEntity : sysTreeTestList) {
            int submenuCount = 0;
            submenuCount = sysTreeTestService.findSubmenuCountByPid(sysTreeTestEntity.getID());
            if (submenuCount > 0) {
                sysTreeTestEntity.setIsLeaf("false");
            } else {
                sysTreeTestEntity.setIsLeaf("true");
            }

        }
        map.put("dataRows", sysTreeTestList);

        return map;

    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("systreetest:info")
    public R info(@PathVariable("id") String id) {
        SysTreeTestEntity sysTreeTest = sysTreeTestService.queryObject(id);

        return R.ok().put("sysTreeTest", sysTreeTest);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("systreetest:save")
    public R save(@RequestBody SysTreeTestEntity sysTreeTest) {
        sysTreeTestService.save(sysTreeTest);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("systreetest:update")
    public R update(@RequestBody SysTreeTestEntity sysTreeTest) {
        sysTreeTestService.update(sysTreeTest);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("systreetest:delete")
    public R delete(@RequestBody String[] ids) {
        sysTreeTestService.deleteBatch(ids);

        return R.ok();
    }

}
